package com.arpa.ntocc.common.common.util;

import com.google.common.base.CaseFormat;
import org.apache.commons.lang3.StringUtils;

/**
 * CommonUtil工具类
 * @Author liuyj
 * @Date 2019-12-04 15:32:29
 */
public class CommonUtil {

    /**
     * 驼峰转下划线
     * 例: TestData -> test_data
     * @return
     */
    public static String camel2Underline(String camelStr){
        String result = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, camelStr);
        return result;
    }

    /**
     * 下划线转驼峰
     * 例: test_data -> testData
     * @return
     */
    public static String underline2Ccamel(String camelStr){
        String result = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, camelStr);
        return result;
    }

    /**
     * 获取文件格式（后缀名）
     * 例: http://third-image.oss-cn-hangzhou.aliyuncs.com/cbf8b51fb46e425dad6677e6e436bb90.png  -> png
     * @return
     */
    public static String fileSuffix(String url){
        String result = "";
        if(StringUtils.isNotEmpty(url)){
            result = url.substring(url.lastIndexOf(".")+1);
        }
        return result;
    }

    private CommonUtil() {
    }
}
